﻿using System;
using System.Collections.Generic;
using System.Text;
using AutoResumeSend.Entity;
using System.Net.Mail;
namespace AutoResumeSend.Componments
{
   public  class SendMailManager
    {
        /// <summary>     
        /// /// 发送邮件     
        /// /// </summary>       
        /// /// <param name="mail">MailEntity实体</param>     
        /// /// <param name="host">邮件服务器</param>      
        /// /// <param name="port">端口</param>       
        /// /// <param name="adminName">权限验证所需的用户名</param>      
        /// /// <param name="adminPassword">权限验证所需的密码</param>        
        public void sendMail(MailInfo mail, string host, int port, string adminName, string adminPassword)
        {
            MailAddress fromAddress = new MailAddress(mail.From, mail.FromDisplayName);
            MailMessage msg = new MailMessage();
            msg.From = fromAddress;
            string[] sendTo = mail.To.Split(';');
            foreach (string temp in sendTo)
            {
                if (temp != string.Empty)
                {
                    msg.Bcc.Add(temp);
                }
            }
            msg.IsBodyHtml = true;
           
            msg.Subject = mail.Subject;
            msg.Body = mail.Body;
            if (mail.Attchments != null && mail.Attchments.Count > 0)
            {
                for (int index = 0; index < mail.Attchments.Count; index++)
                {
                    msg.Attachments.Add(mail.Attchments[index]);
                }
            }

            SmtpClient smtpClient = new SmtpClient(host, port);
            smtpClient.Credentials = new System.Net.NetworkCredential(adminName, adminPassword);
            smtpClient.Send(msg);
        }
    }
}
